package com.zufe.springdemo.controller;

import com.sun.org.apache.regexp.internal.RE;
import com.zufe.springdemo.model.Information;
import com.zufe.springdemo.model.User;
import com.zufe.springdemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    UserService userService;
    @RequestMapping("/showAllUser")
    public String showAllUser()
    {
        List<User> list = userService.selectAllUser();
        String userList="";
        for (int i = 0;i < list.size();i++)
        {
            userList += list.get(i).toString();
        }
        return userList;
    }

    @RequestMapping("/showOneUser/{userId}")
    public String showOneUser(@PathVariable(name = "userId") int userId)
    {
        User user = userService.selectUser(userId);
        return user.toString();
    }

    @RequestMapping("showLeftOnUser")
    public String showLeftOnUser()
    {
        List<Information> list = userService.selectLeftOnUser();
        String userList="";
        for (int i = 0;i < list.size();i++)
        {
            userList += list.get(i).toString();
        }
        return userList;
    }
}
